/*
 * 项   目：spring-boot-demo
 * 作   者：罗毅（ymluo） 
 * 邮   箱：ymluo@iflytek.com
 * 创建时间：2017/11/15 9:28
 */
package com.roin.learn.springboot.demo.api;

import com.roin.learn.springboot.demo.entity.User;
import com.roin.learn.springboot.demo.mapper.UserMapper;
import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {
    @Value(value = "${book.author}")
    private String bookAuthor;
    @Value("${book.name}")
    private String bookName;
    @Value("${book.pinyin}")
    private String bookPinYin;

    @Autowired
    UserMapper userMapper;



//    @RequestMapping(value = "/users",produces = "text/plain;charset=UTF-8",method = RequestMethod.GET)
    @RequestMapping(value = "/users",produces = "application/json; charset=utf-8",method = RequestMethod.GET)
    List<User> getUsers(){
        return userMapper.getAll();
    }

    @RequestMapping(value = "/users",produces = "application/json; charset=utf-8",method = RequestMethod.POST)
    User save(User user, HttpResponse response){
        userMapper.insert(user);
        return userMapper.getByUserId(user.getUserId());
    }
}
